/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from 'vue'
import {Tooltip} from "view-design";

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {
  //搜索条件
  modalSearch: {
    isShow: false,
  },
  //搜索条件
  modalDetail: {
    isShow: false,
    title:""
  },
};

// 和网络交互相关的参数
let params = {
  //搜索条件
  searchParams:{
    startCreatedate:"",
    endCreatedate:"",
  },
  detailParams:{
    inputKeyword:"",
    page:{
      total: 1,
      startIndex: 0,
      stepNumber: 40,
      currentPage: 1
    }
  },
  startEndDate: [],
};

// 页面的数据源
let data = {
  keyWordList: [],
  keyWordDetailList:[],
  dateRange: {
    disabledDate (date) {
      return date && date.valueOf() > Date.now() - 86400000;
    }
  },
};

let table = function (self) {
  let titles = [
    {
      type: 'index',
      title: '#',
      align: 'center',
      width: 60
    },
    {
      title: '用户输入关键词',
      key: 'inputKeyword',
      align: 'center',
      minWidth: 150,
    },
    {
      title: '搜索关键词',
      key: 'searchKeyword',
      align: 'left',
      minWidth: 150,
    },
    {
      title: '搜索次数',
      key: 'searchCount',
      width: 120,
      align: 'center',
      render: (h, params) => {
        return (
          <div>
            <a style="padding:6px;font-size:13px;color:#448aff" onClick={() => {
              self.getKeywordDetail(params.row.inputKeyword);
            }}>
              {params.row.searchCount}
            </a>
          </div>);
      }

    }
  ]

  return self.$authTableTitles(titles)
}

let detailTable = function (self) {
  let titles = [
    {
      type: 'index',
      title: '#',
      align: 'center',
      width: 60
    },
    {
      title: '用户名',
      key: 'userName',
      align: 'center',
      render: (h, params) => {
        let hideName = Vue.prototype.$tiyHideUsername(params.row.userName);
        return h('span',hideName)
      }
    },
    {
      title: '输入关键词',
      key: 'inputKeyword',
      align: 'left'
    },
    {
      title: '搜索关键词',
      key: 'searchKeyword',
      width: 120,
      align: 'center',
    },
    {
      title: '返回结果数',
      key: 'result',
      width: 120,
      align: 'center',
    },
    {
      title: '搜索时间',
      key: 'createtime',
      width: 160,
      align: 'center',
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.createtime));
      }
    },
    {
      title: '终端类型',
      key: 'deviceType',
      width: 120,
      align: 'center',
      render: (h, params) => {
        let device = '';
        switch(params.row.deviceType){
          case 1:
            device = 'Android';
            break;
          case 2:
            device = 'IOS';
            break;
          case 3:
            device = 'PC';
            break;
          case 4:
            device = 'Mobile PC';
            break;
          default:
            break;
        }
        return h('div', device);
      }
    }
  ]

  return self.$authTableTitles(titles)
}

export default  {
  tPage: page,
  tParams: params,
  tStatus: status,
  tableTitles: table,
  detailTableTitles: detailTable,
  tData: data
};
